export default {
	data() {
		return {
			loadMore: 'loadmore',
			statusBarHeight: 0,
			safeAreaBottom: 0,
			dataList: [],
			contentHeight: 0,
			current: 1,
		}
	},
	created() {
		this.init()
	},
	methods: {
		onRefresh(current, size) {
			this.current = current
			setTimeout(() => {
				this.$refs.paging.complete()
			}, 2000)
			// this.getDataList(true)
		},
		onLoadMore() {
		  if(!this.isRequest) {
		    this.isRequest = true
		    this.current++
		    // this.getDataList(false)
		  }
		},
		onScroll(e) {
			this.$refs.paging.endRefresh()
		  const { deltaY, scrollTop, scrollHeight } = e.target
		  if(deltaY < 0 && scrollHeight - this.contentHeight - scrollTop < 50 && this.loadMore == 'loadmore') {  //向下滑动
		    this.timer && clearTimeout(this.timer)
		    this.timer = setTimeout(() => {
		      this.loadMore = 'loading'
		      // this.onLoadMore()
		    }, 300);
		  }
		},
		init() {
			const rs = uni.getSystemInfoSync()
			this.statusBarHeight = rs.statusBarHeight
			this.safeAreaBottom = rs.safeAreaInsets.bottom
		},
		setContentHeight(className) {
			const dom = uni.createSelectorQuery().in(this).select(className)
			dom.boundingClientRect((info) => {
			  this.contentHeight = info.height
			}).exec()
		}
	},
	beforeDestroy() {
		this.timer && clearTimeout(this.timer)
	}
}